using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Redirect("Products.aspx?CategoryID=All");
     
        if (!IsPostBack)
        {
            this.FillCategories();
        }
    }

    void FillCategories()
    {
        String sql = "SELECT * FROM Categories";
        DataTable Categories = Database.GetData(sql);

        DataList1.DataSource = Categories;
        DataList1.DataBind();
    }

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        GridView GridView1 = (GridView)e.Item.FindControl("GridView1");
        DataRowView RowView = (DataRowView)e.Item.DataItem;

        int CategoryID = (int)RowView.Row["CategoryID"];
        String sql = "SELECT TOP 3 * FROM Products WHERE CategoryID=@CategoryID";
        DataTable Products = Database.GetData(sql, "@CategoryID", CategoryID);

        GridView1.DataSource = Products;
        GridView1.DataBind();
    }
}
